package com.wnxy.sddfp.system.controller;


import com.wnxy.sddfp.common.model.dto.bank.CardBindDTO;
import com.wnxy.sddfp.common.model.dto.bank.SignatureDTO;
import com.wnxy.sddfp.common.model.dto.user.LoginDto;
import com.wnxy.sddfp.common.model.dto.user.UserRegistDto;
import com.wnxy.sddfp.common.model.vo.user.LoginVo;
import com.wnxy.sddfp.common.model.vo.user.UserInfoVo;
import com.wnxy.sddfp.common.result.Result;
import com.wnxy.sddfp.system.service.IUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 用户模块
 */
@RestController
@RequestMapping("/user")
@Slf4j
@Api(tags = "用户模块")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * 用户注册
     */
    @PostMapping("/regist")
    @ApiOperation("用户注册") // hibernate-validate
    public Result regist(@RequestBody @Valid UserRegistDto userRegistDto){
        userService.regist(userRegistDto);
        return Result.ok();
    }

    /**
     * 用户登录
     */
    @PostMapping("/login")
    public Result<LoginVo> login(@RequestBody LoginDto loginDto) {
        LoginVo loginVo = userService.login(loginDto);
        return Result.ok(loginVo);
    }

    /**
     * 用户绑卡接口
     */
    @PostMapping("/bank/card/add")
    public Result<SignatureDTO> addBankAccount(@RequestBody CardBindDTO cardBindDTO) {
        return userService.addBankAccount(cardBindDTO);
    }

    /**
     * 根据用户id查询
     */
    @PostMapping("/inner/{id}")
    public Result<UserInfoVo> queryUserById(@PathVariable("id") Long id) {
        UserInfoVo userInfoVo = userService.queryUserById(id);
        return Result.ok(userInfoVo);
    }
}















